config: refactor parse_leasetime() - branch amount remains same
authorPaul Donald <[email protected]>
Fri, 3 Oct 2025 14:33:32 +0000 (16:33 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 13 Oct 2025 07:51:58 +0000 (09:51 +0200)
Also make 's' value a noop.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/225
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c

index cfc0af64917b679d1c5c93e70fd7b8f1a33ccab3..8a7a9c3d8aaf2459d9ccf45727117520ee95b439 100644 (file)
@@ -431,18 +431,14 @@ static double parse_leasetime(struct blob_attr *c) {
        double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX;
 
        if (time && endptr && endptr[0]) {
-               if (endptr[0] == 's')
-                       time *= 1;
-               else if (endptr[0] == 'm')
-                       time *= 60;
-               else if (endptr[0] == 'h')
-                       time *= 3600;
-               else if (endptr[0] == 'd')
-                       time *= 24 * 3600;
-               else if (endptr[0] == 'w')
-                       time *= 7 * 24 * 3600;
-               else
-                       goto err;
+               switch(endptr[0]) {
+                       case 's': break; /* seconds */
+                       case 'm': time *= 60; break; /* minutes */
+                       case 'h': time *= 3600; break; /* hours */
+                       case 'd': time *= 24 * 3600; break; /* days */
+                       case 'w': time *= 7 * 24 * 3600; break; /* weeks */
+                       default: goto err;
+               }
        }
 
        if (time < 60)